package observers;

import configuration.Configuration;
import game.User; 
import game.Player; 
import java.io.File;
import highscore.SimpleWriteRead; 
import java.io.IOException; 
import java.io.FileNotFoundException; 

public class PlayerOneObserver implements Observer {
	
	private File UserActionLog; 
	
	public void processEvent(Event e) throws IOException, FileNotFoundException{
		if(e instanceof PlayerMoveEvent && ((PlayerMoveEvent)e).getPlayer() instanceof User){
			Configuration config = Configuration.getInstance(); 
			System.out.println("PlayerObserver" + e.getMessage());
			UserActionLog = config.getFileConfiguration(); 
			if(!UserActionLog.exists()){ 
				throw new FileNotFoundException("File not found!"); 
			} else{ 
				StringBuilder stringBuilder = new StringBuilder(); 
				String fileString = "" + SimpleWriteRead.getContents(UserActionLog); 
				fileString = fileString + stringBuilder.append(e.getMessage()); 
				SimpleWriteRead.setContents(UserActionLog, fileString);
			}
		}	
	}
}
